package com.theaf.basemodule.web.controller;

import com.theaf.basemodule.common.api.ParameterService;
import com.theaf.basemodule.common.condition.ParaCondition;
import com.theaf.basemodule.common.vo.ParameterVO;
import com.theaf.core.web.ResultHandler;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:songwenke
 * @Description:参数Controller
 * @Date:create in 16:15 2017/12/25
 * @Modified By:
 **/
@RestController
@RequestMapping(value="/para")
@Api(description="参数controller")
public class ParaController {
    @Autowired
    private ParameterService parameterService;

    @RequestMapping(value = "/list",  method = RequestMethod.POST)
    @ApiOperation(value = "参数查询", notes = "参数查询", response = ParameterVO.class)
    public Object list(@RequestBody @ApiParam(name="查询条件",value="传入json格式",required=true) ParaCondition condition){
        return ResultHandler.success(parameterService.findByCondition(condition));
    }

    @RequestMapping(value = "/get/{code}",  method = RequestMethod.PUT)
    @ApiOperation(value = "获取参数", notes = "获取参数", response = ParameterVO.class)
    @ApiImplicitParam(value = "参数标识" , name = "code" , dataType = "string" , paramType = "path" ,required=true)
    public Object get(@PathVariable("code") String code){
        return ResultHandler.success(parameterService.findByCode(code));
    }

    @RequestMapping(value = "/save",  method = RequestMethod.POST)
    @ApiOperation(value = "保存参数", notes = "保存参数", response = String.class)
    public Object save(@RequestBody @ApiParam(name="参数数据",value="传入json格式",required=true) ParameterVO parameterVO){
        parameterService.save(parameterVO);
        return ResultHandler.success(true);
    }

    @RequestMapping(value = "/delete/{code}",  method = RequestMethod.PUT)
    @ApiOperation(value = "删除参数", notes = "保存参数", response = Boolean.class)
    @ApiImplicitParam(value = "参数标识" , name = "code" , dataType = "string" , paramType = "path",required=true)
    public Object delete(@PathVariable("code") String code){
        parameterService.delete(code);
        return ResultHandler.success(true);
    }

}
